/*
 Copyright (c) 2011, fisamo
 All rights reserved.

 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are met:

 Redistributions of source code must retain the above copyright notice, this
 list of conditions and the following disclaimer.
 Redistributions in binary form must reproduce the above copyright notice, this
 list of conditions and the following disclaimer in the documentation and/or
 other materials provided with the distribution.
 Neither the name of the fisamo nor the names of its contributors may be used
 to endorse or promote products derived from this software without specific
 prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef SOURCE_LME_H_
#define SOURCE_LME_H_

#include <vector>

#include "opencv/cv.h"
#include "opencv/highgui.h"

namespace lme
{
class CEntropyStruct;

class Clme
{
 public:

	Clme();

	~Clme();

	VOID Inicio(const cv::Mat & aImage);

	VOID Tracing(cv::Mat & aImage);

	VOID SetPixelDistance(Pixel aPixel);
	Pixel GetPixelDistance() const;

	VOID SetConcaveTolerance(const Tolerance & aConcaveTolerance);
	VOID SetConvexTolerance(const Tolerance & aConvexTolerance);

	Tolerance GetConcaveTolerance();
	Tolerance GetConvexTolerance();

	Angle CalculateAngle(Point ap1, Point ap2, Point ap3) const;

 private:

	VOID AdjustEntropies(Tolerance aTolx, Tolerance aToly);
	VOID AdjustEntropy(lme::CEntropyStruct * aEntropyStruct);

	VOID Window3(cv::Mat & aBinaryImg);
	VOID Windows(cv::Mat & aBinaryImg);

	FLOAT CalculateEntropy(const FLOAT & aEntropy) const;
	VOID CalculatePointStrength();

	VOID CalculateDominatPoint();

	VOID CalculateHistogram();

	/** Checks if a given object matches the template */
	BOOL Match();

	/** Calculates Manhattan distance between two points */
	Pixel ManhattanDistance(Point aPt1, Point aPt2) const;

	static const Tolerance MinimumEntropy = 0.5;
	static const Tolerance MaximumEntropy = 0.955;
	static const Angle PI = 3.14159265;

	// Store convex tolerance parameter
	Tolerance m_ConvexTolerance;

	// Store concave tolerance parameter
	Tolerance m_ConcaveTolerance;

	Pixel m_PixelDistance;

	std::vector<CEntropyStruct *> m_EntropyList;

	cv::MatND standard;

	cv::MatND hist;

};
}
#endif  // SOURCE_LME_H_
